package com.siysoft.tc.admin.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.siysoft.tc.admin.service.IAdminReservationService;
import com.siysoft.tc.base.bean.to.Reservation;
import com.siysoft.util.COMMON;
import com.siysoft.util.IMap;
import com.tc.base.dao.BaseDAO;

/**
 * 方法摘要：实现后台管理员管理功能接口 作者：zhouyu 日期：2015年6月5日
 * 
 * @param iMap
 * @return
 * @throws Exception
 */

@Service
public class AdminReservationServiceImpl implements
		IAdminReservationService {
	@Autowired
	BaseDAO baseDao;

	@Override
	public List<Map<String, Object>> seekReservations(IMap iMap) throws Exception {
		// TODO Auto-generated method stub
		String hql = "select * from v_reservation order by reservation_id desc ";
		return (List<Map<String, Object>>) baseDao.findBySQLToMap(hql, null, -1, -1);
	}
	

	@Override
	public List<Map<String, Object>> seekReservationsApprove(IMap iMap)
			throws Exception {
		// TODO Auto-generated method stub
		String hql = "select * from v_reservation where reservation_status = 1 order by reservation_id desc ";
		return (List<Map<String, Object>>) baseDao.findBySQLToMap(hql, null, -1, -1);
	}

	@Override
	public List<Map<String, Object>> seekReservationsAdmin(IMap iMap)
			throws Exception {
		// TODO Auto-generated method stub
		String hql = "select * from v_reservation where reservation_administrator = 1 order by reservation_id desc ";
		return (List<Map<String, Object>>) baseDao.findBySQLToMap(hql, null, -1, -1);
	}

	@Override
	public Map<String, String> toReservationRevise(IMap iMap) throws Exception  {
		// TODO Auto-generated method stub
		String hql = "select * from v_reservation where reservation_id = "
				+ iMap.getInt("reservation_id") + " ";
		// 将查询结果存到list下
		List list = baseDao.findBySQLToMap(hql, iMap, -1, -1);
		// 判断list中是否存在数据
		if (list.size() > 0) {
			// list中存在数据返回list第一条数据
			return (Map<String, String>) list.get(0);
		} else {
			return null;
		}
	}

	@Override
	public void reviseReservationInfo(IMap iMap) throws Exception  {
		// TODO Auto-generated method stub
		Reservation rs = (Reservation)baseDao.findById(Reservation.class, iMap.getInt("reservation_id"));
		String reservation_address = iMap.getString("reservation_address");
		if(!COMMON.isnull(reservation_address))rs.setReservation_address(reservation_address);
		Integer reservation_administrator = iMap.getInt("reservation_administrator");
		if(!COMMON.isnull(reservation_administrator))rs.setReservation_administrator(reservation_administrator);
		Integer reservation_bonus = iMap.getInt("reservation_bonus");
		if(!COMMON.isnull(reservation_bonus))rs.setReservation_bonus(reservation_bonus);
		String reservation_course = iMap.getString("reservation_course");
		if(!COMMON.isnull(reservation_course))rs.setReservation_course(reservation_course);
		int reservation_create_id = iMap.getInt("reservation_create_id");
		if(!COMMON.isnull(reservation_create_id))rs.setReservation_create_id(reservation_create_id);
		Integer reservation_current_size = iMap.getInt("reservation_current_size");
		if(!COMMON.isnull(reservation_current_size))rs.setReservation_current_size(reservation_current_size);
		Integer reservation_goal = iMap.getInt("reservation_goal");
		if(!COMMON.isnull(reservation_goal))rs.setReservation_goal(reservation_goal);
		Integer reservation_ispublic = iMap.getInt("reservation_ispublic");
		if(!COMMON.isnull(reservation_ispublic))rs.setReservation_ispublic(reservation_ispublic);
		Integer reservation_lecture_id = iMap.getInt("reservation_lecture_id");
		if(!COMMON.isnull(reservation_lecture_id))rs.setReservation_lecture_id(reservation_lecture_id);
		Integer reservation_max_size = iMap.getInt("reservation_max_size");
		if(!COMMON.isnull(reservation_max_size))rs.setReservation_max_size(reservation_max_size);
		String reservation_number = iMap.getString("reservation_number");
		if(!COMMON.isnull(reservation_number))rs.setReservation_number(reservation_number);
		Integer reservation_period = iMap.getInt("reservation_period");
		if(!COMMON.isnull(reservation_period))rs.setReservation_period(reservation_period);
		Integer reservation_recommend_index = iMap.getInt("reservation_recommend_index");
		if(!COMMON.isnull(reservation_recommend_index))rs.setReservation_recommend_index(reservation_recommend_index);
		String reservation_school = iMap.getString("reservation_school");
		if(!COMMON.isnull(reservation_school))rs.setReservation_school(reservation_school);
		/* 这块交给罗特来修改。建议写一个全局函数。
		 * Integer reservation_status;
		if(!COMMON.isnull(reservation_status))rs.setReservation_status(reservation_status);*/
		Integer reservation_wage = iMap.getInt("reservation_wage");
		if(!COMMON.isnull(reservation_wage))rs.setReservation_wage(reservation_wage);
		baseDao.save(rs);
	}


	

	
		
}
